﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Vit.Common;

namespace Vit.Database.DataAccess
{
    public class PropertyAccessibleRowMapper<TResult> : IRowMapper<TResult>
        where TResult : IPropertyAccessible, new()
    {
        #region IRowMapper<TResult> Members

        public TResult MapRow(IDataRecord row)
        {
            TResult obj = new TResult();
            for(int i=0; i<row.FieldCount; i++)
            {
                string colName = row.GetName(i);
                obj.SetPropertyValue(colName, row[i]);
            }
            return obj;
        }

        #endregion
    }
}
